<?php
	namespace Vue;
	class Vue {
		private $page;
		public function __construct($page){
			$this->page = $page;
		}
		public function display($format){
			$xml = $this->page->toXML();
			$xml->getElementsByTagName('site')->item(0)->setAttribute('url','http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
			$xml->preserveWhiteSpace = false;
			$xml->formatOutput = true; 

			$xsl = $this->page->getXSL($format);

			$proc = new \XSLTProcessor();
			$proc->importStyleSheet($xsl);

			//echo $xml->saveXML();
			//echo $proc->transformToXML($xml);
			$res = $proc->transformToDoc($xml);
			$res->formatOutput = true;
			$out = $res->saveXML();
			if($format == 'html'){
				echo str_replace('<?xml version="1.0" encoding="UTF-8"?>','<!DOCTYPE html>',$out);
			}
			else{
				echo $out;
			}
		}
		public function move($page){
			header('HTTP/1.1 302');
			header('Location: http://'.$_SERVER['SERVER_NAME'].'/'.$page);
		}
	}
?>
